package com.studyadmin.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.studyadmin.config.QueryPageParam;
import com.studyadmin.entity.Chapter;
import com.studyadmin.entity.ChapterContent;
import com.studyadmin.entity.Student;
import com.studyadmin.service.ChapterService;
import com.studyadmin.util.JsonUtil;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.HashMap;

/**
 * <p>
 * 章节表 前端控制器
 * </p>
 *
 * @author lyl
 * @since 2023-03-19
 */
@RestController
@RequestMapping("/studyadmin/chapter")
@CrossOrigin
public class ChapterController {

    @Autowired
    ChapterService chapterService;

    /**
     * 学生端课程的学习 //教师端，章节内容
     * @param CourseId 课程id
     * @return 结果
     */
    @GetMapping ("/chapterByCourseId")
    public JsonUtil chapterByCourseId(@RequestParam(value = "courseId") String CourseId){
        System.out.println(CourseId);
        return chapterService.chByCouIdSer(CourseId);
    }
    /**
     * 根据章节ID查询章节内容
     * @param chaId
     * @return 结果
     */
    @GetMapping ("/chapterContentAll")
    public JsonUtil chapterContentAll(@RequestParam(value = "chaId") String chaId){
        System.out.println("章节内容id"+chaId);
        return chapterService.chapterContentSer(chaId);
    }

    @PostMapping("/chapterContentUpdate")
    public JsonUtil chapterContentUpdate(@RequestBody ChapterContent chapterContent) {
        return chapterService.ChapterUpdateSer(chapterContent);


    }

    /**
     * 根据章节ID查询章节内容 //分页查询 改进
     * @param query 分页数据
     * @return 结果
     */
    @PostMapping("/chapterContent")
    public JsonUtil chapterContent(@RequestBody QueryPageParam query) {
        return chapterService.pageChapterSer(query);
    }


    /**
     * 添加章节名称
     * @param chaName
     * courseId 课程id
     * @return 结果
     */
    @GetMapping ("/addChapter")
    public JsonUtil addChapter(@RequestParam(value = "chaName") String chaName,
                               @RequestParam(value = "courseId") String courseId){
        Chapter chapter = new Chapter();
        chapter.setChaName(chaName);
        chapter.setCourseId(Integer.valueOf(courseId));
        return chapterService.addChapterSer(chapter);
    }

    /**
     * 删除章节
     * @param chaId
     * courseId 课程id
     * @return 结果
     */
    @GetMapping ("/delChapter")
    public JsonUtil addChapter(@RequestParam(value = "chaId") String chaId){
        Chapter chapter = new Chapter();
        chapter.setChaId(Integer.parseInt(chaId));
        return chapterService.delChapterSer(chapter);
    }







}

